<template>
  <div>
    <el-dialog :visible="true" title="编辑" width="60%" :before-close="callOf" center>
      <el-form ref="form" :model="sizeForms" label-width="100px" size="mini" :rules="formrules2">
        <el-form-item label="任务名称" prop="task_name">
          <el-input ref="task_name" v-model="sizeForms.task_name" placeholder="请输入任务名称" style="width:50%" class="add" />
        </el-form-item>
        <el-form-item label="工作名称" prop="job_name">
          <el-input ref="job_name" v-model="sizeForms.job_name" placeholder="请输入工作名称" style="width:50%" />
        </el-form-item>
        <el-form-item label="token" prop="ding_token">
          <el-input ref="ding_token" v-model="sizeForms.ding_token" type="textarea" :rows="3" placeholder="请输入token值" style="width:80%" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="dialogFormEdit('form')">保存</el-button>
          <el-button type="primary" @click="callOf('form')">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>
<script>
import { uptask_byid } from '@/api/ci'
export default {
  name: 'Edit',
  props: {
    sizeForms: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      formrules2: {
        task_name: [{ required: true, message: '任务名称不能为空', trigger: 'blur' }],
        job_name: [{ required: true, message: '工作名称不能为空', trigger: 'blur' }],
        ding_token: [{ required: true, message: 'token不能为空', trigger: 'blur' }]
      }
    }
  },
  methods: {
    dialogFormEdit(form) {
      this.$refs[form].validate((valid) => {
        if (valid) {
          console.log(this.sizeForms)
          uptask_byid({
            id: this.sizeForms.id,
            task_name: this.sizeForms.task_name,
            job_name: this.sizeForms.job_name,
            ding_token: this.sizeForms.ding_token,
            status: this.sizeForms.status
          })
            .then(res => {
              this.$message({
                type: 'success',
                message: '编辑成功'
              })
              this.callOf()
              this.$emit('update')
            })
        } else {
          return false
        }
      })
    },
    callOf() {
      this.$emit('closePop')
    }
  }
}

</script>
